//
//  LYQMineDemandManageViewController.m
//  ZCProject
//
//  Created by Zheng on 2016/12/20.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQMineDemandManageViewController.h"

#import "LYQDemandManageHeaderCell.h"
#import "LYQDemandManageContentInfoCell.h"
#import "LYQDemandManageFooterCell.h"

#define kLYQDemandManageHeaderCell_ID @"kLYQDemandManageHeaderCell_ID"
#define kLYQDemandManageContentInfoCell_ID @"kLYQDemandManageContentInfoCell_ID"
#define kLYQDemandManageFooterCell_ID @"kLYQDemandManageFooterCell_ID"

@interface LYQMineDemandManageViewController () <UITableViewDelegate, UITableViewDataSource>

@end

@implementation LYQMineDemandManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"我的需求";
    
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    self.listTableView.estimatedRowHeight = 100;
    self.listTableView.rowHeight = UITableViewAutomaticDimension;
    self.listTableView.sectionFooterHeight = 0.0001f;
    [self.listTableView registerClass:[LYQDemandManageHeaderCell class] forCellReuseIdentifier:kLYQDemandManageHeaderCell_ID];
    [self.listTableView registerNib:[UINib nibWithNibName:@"LYQDemandManageContentInfoCell" bundle:nil] forCellReuseIdentifier:kLYQDemandManageContentInfoCell_ID];
    [self.listTableView registerClass:[LYQDemandManageFooterCell class] forCellReuseIdentifier:kLYQDemandManageFooterCell_ID];
    
}

#pragma mark - tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        NSArray *titles = @[@"寻找意大利地接社",@"新开北京-美国包机, 求合作批发商"];
        
        LYQDemandManageHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:kLYQDemandManageHeaderCell_ID forIndexPath:indexPath];
        cell.titleLbl.text = titles[indexPath.section];
        
        return cell;
    } else if (indexPath.row == 1) {
        
        NSArray *titles = @[@"10月12日,我们有一个xx人的团去xxx.我们需要资源/服务.希望与您合作,提供相关资料.",
                            @"与美国航空公司合作,计划新开北京-洛杉矶暑假包机业务,希望与专线批发商合作."];
        
        NSMutableAttributedString *contentStr = [[NSMutableAttributedString alloc] initWithString:titles[indexPath.section]];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:5];
        [contentStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [contentStr length])];

        
        LYQDemandManageContentInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kLYQDemandManageContentInfoCell_ID forIndexPath:indexPath];
        
        cell.contentInfoLbl.attributedText = contentStr;
        
        return cell;
    } else {
        
        LYQDemandManageFooterCell *cell = [tableView dequeueReusableCellWithIdentifier:kLYQDemandManageFooterCell_ID forIndexPath:indexPath];
        return cell;
        
    }
    
}

#pragma mark - tableview delegate
#pragma mark 头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kWScale(10);
}

#pragma mark 分割线偏移量
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UIEdgeInsets insets = UIEdgeInsetsZero;
    
    if (indexPath.row == 0) {
        insets = UIEdgeInsetsMake(0, kWScale(75), 0, 0);
    } else {
        insets = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:insets];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:insets];
    }
}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
